package zdream.pmfield.stage.buff.disease;

import zdream.pmfield.data.foe.MoveAdditionalEffects;
import zdream.pmfield.data.foe.VStat;
import zdream.pmfield.stage.buff.foe.FoeStageBuff;
import zdream.pmfield.stage.director.HookType;
import zdream.pmfield.stage.director.Hooks;
import zdream.pmfield.stage.object.FoeActor;

/**
 * <p>中毒状态 (本作没有猛毒 / 剧毒)
 * <p>参考 For The King 2 的效果, 中毒时,
 * 除幸运以外的所有 {@link zdream.pmfield.data.foe.VStat} 能力值下降 10, 但不扣血.
 * 该状态不会随时间恢复
 * </p>
 *
 * @author Zdream
 * @date 2023-12-03
 * @since 0.0.1
 */
public class PoisonedBuff extends FoeStageBuff {
	public static final String CATEGORY = MoveAdditionalEffects.E_POISONED;

	public PoisonedBuff(FoeActor target) {
		super(target);
	}

	@Override
	public void init() {
		preventSameBuffBeforeFoeReceiveBuff();
		onHook(HookType.ON_FOE_REFRESH_VSTAT)
				.handle(this::reduceVStat)
				.withPriority(-900)
				.buildAndSave();

		target.refreshVStat();
	}

	@Override
	public void destroy() {
		super.destroy();
		target.refreshVStat();
	}

	public void reduceVStat(Hooks.HookContext rawContext) {
		Hooks.FoeBuffContext context = rawContext.as();
		if (context.foe != target) {
			return;
		}

		final short[] vStats = target.vStats;
		for (int i = 0; i < vStats.length; i++) {
			if (i == VStat.LUCK.ordinal()) {
				continue;
			}
			vStats[i] -= 10;
		}
	}

	@Override
	public String getCategory() {
		return CATEGORY;
	}

	@Override
	public String toString() {
		return "中毒";
	}
}
